﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.BillingServiceRef;

    public class BillingServiceClientProxy : BasePage
    {
        public string DeleteAccessorialCharges(List<string> IDS)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.DeleteAccessorialCharges(IDS, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteInvoice(InvoiceInfo invoiceInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.DeleteInvoice(invoiceInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteInvoiceDetail(List<string> invoiceID, List<string> lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.DeleteInvoiceDetail(invoiceID, lineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteStatement(List<string> IDS)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.DeleteStatement(IDS, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string DeleteStatementDetail(string StatementID, List<string> LineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.DeleteStatementDetail(StatementID, LineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string GenerateBillingCredence(List<string> docID, List<string> docType)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.GenerateBillingCredence(docID, docType, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string GenerateDailyInvBillingCredence(string ownerID, List<string> days)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.GenerateDailyInvBillingCredence(ownerID, days, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string GenerateStorageChargesBillingCredence(string days, List<string> ownerID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.GenerateStorageChargesBillingCredence(days, ownerID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public AccessorialChargesOrderInfo GetAccessorialChargesByID(string orderID, string accessorialType)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            AccessorialChargesOrderInfo accessorialChargesOrderInfo = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                accessorialChargesOrderInfo = client.GetAccessorialChargesByID(orderID, accessorialType, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return accessorialChargesOrderInfo;
        }

        public DataSet GetAccessorialChargesByQueryList(AccessorialChargesQueryEntity accessorialChargesQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                ds = client.GetAccessorialChargesByQueryList(accessorialChargesQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetBillingCredenceByQueryList(BillingCredenceQueryEntity billingCredenceQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                ds = client.GetBillingCredenceByQueryList(billingCredenceQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetBillingCredenceByStatementID(string statementID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                ds = client.GetBillingCredenceByStatementID(statementID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetBillingCredenceGroupByQueryList(BillingCredenceQueryEntity billingCredenceQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                ds = client.GetBillingCredenceGroupByQueryList(billingCredenceQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetBillingDailyInvByQueryList(BillingDailyInvQueryEntity billingDailyInvQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                ds = client.GetBillingDailyInvByQueryList(billingDailyInvQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public DataSet GetBillingOrderByQueryList(BillingOrderQueryEntity billingOrderQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                ds = client.GetBillingOrderByQueryList(billingOrderQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public static BillingServiceClientProxy GetInstance()
        {
            return new BillingServiceClientProxy();
        }

        public InvoiceInfo GetInvoiceByID(string InvoiceID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            InvoiceInfo invoiceInfo = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                invoiceInfo = client.GetInvoiceByID(InvoiceID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return invoiceInfo;
        }

        public DataSet GetInvoiceByQueryList(InvoiceQueryEntity invoiceQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                ds = client.GetInvoiceByQueryList(invoiceQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public InvoiceDetailInfo GetInvoiceDetailInfoByID(string invoiceID, string lineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            InvoiceDetailInfo invoiceDetailInfo = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                invoiceDetailInfo = client.GetInvoiceDetailInfoByID(invoiceID, lineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return invoiceDetailInfo;
        }

        public StatementInfo GetStatementByID(string orderID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            StatementInfo statementInfo = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                statementInfo = client.GetStatementByID(orderID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return statementInfo;
        }

        public DataSet GetStatementByQueryList(StatementQueryEntity statementQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                ds = client.GetStatementByQueryList(statementQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public StatementDetailInfo GetStatementDetailInfoByID(string StatementID, string LineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            StatementDetailInfo statementDetailInfo = null;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                statementDetailInfo = client.GetStatementDetailInfoByID(StatementID, LineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return statementDetailInfo;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertAccessorialCharges(AccessorialChargesInfo accessorialChargesInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.InsertAccessorialCharges(accessorialChargesInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertInvoice(InvoiceInfo invoiceInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.InsertInvoice(invoiceInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertInvoiceDetail(InvoiceDetailInfo invoiceDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.InsertInvoiceDetail(invoiceDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertInvoicePaymentDetail(List<InvoicePaymentDetailInfo> invoicePaymentDetailListInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.InsertInvoicePaymentDetail(invoicePaymentDetailListInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertStatement(StatementInfo StatementInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.InsertStatement(StatementInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateBillingCredencePrintDate(List<BillingCredenceInfo> billingCredenceInfos)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.UpdateBillingCredencePrintDate(billingCredenceInfos, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateInvoice(InvoiceInfo invoiceInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.UpdateInvoice(invoiceInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateInvoiceSubmit(List<InvoiceInfo> invoiceListInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.UpdateInvoiceSubmit(invoiceListInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateStatement(StatementInfo StatementInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.UpdateStatement(StatementInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateStatementDetailReceived(StatementDetailInfo statementDetailInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.UpdateStatementDetailReceived(statementDetailInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateStatementStatus(StatementInfo StatementInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            BillingServiceClient client = new BillingServiceClient("WSHttpBinding_IBillingService");
            try
            {
                result = client.UpdateStatementStatus(StatementInfo, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

